// mircoApp/competitionApply/applyDetails/applyDetails.js
const app = getApp();
const skinBehavior = require("../../../utils/themeSkin/skinBehavior");
Page({
  behaviors: [skinBehavior],
  /**
   * 页面的初始数据
   */
  data: {
    Hei:'', //轮播图自适应图片
    imgheights:[],
    imgBoxSize:'',
    status:1,
    slideBanner:[
      {
        image_url:'https://dev8.yunzmall.com/static/upload/image/803deae708f9e2ce52f8c9f20ea77537.jpg'
      }
    ],
    applyInfo:{},
    id:'',
    endTime:'',
    timeData:{},
    showKefu:false,
    customer_open:false,
    service_QRcode:'',
    service_mobile:'',
    iPnoneBottomBol: false, //是否是苹果手机
    imgPath: app.globalData.imgPath,
    posterShow:false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    if(options.id) {
      this.setData({
        id:options.id
      })
      this.goodsDetail();
      this.serviceDetail();
      this.getiPnoneBottom();
    }
  },
  getiPnoneBottom() {
    let that = this;
    try {
      let value = wx.getStorageSync('iPhoneBottom');
      if (value) {
        that.setData({
          iPnoneBottomBol: true
        });
        // Do something with return value
      }
    } catch (e) {
      // Do something when catch error
    }
  },
  applyOn() {
    wx.navigateTo({
      url:`/mircoApp/competitionApply/applyForm/applyForm?goodsId=${this.data.applyInfo.id}&title=${this.data.applyInfo.title}`
    })
  },
  onChange(e) {
    this.setData({
      timeData: e.detail,
    });
  },
  onService() { //点赞功能
    this.setData({
     showKefu:true
    })
   },
  imgH(e){
    var winWid = wx.getSystemInfoSync().windowWidth;//获取当前屏幕的宽度
    var imgh=e.detail.height;//图片高度
    var imgw=e.detail.width;
    var swiperH=winWid*imgh/imgw;　//等比设置swiper的高度。  即 屏幕宽度 / swiper高度 = 图片宽度 / 图片高度    ==》swiper高度 = 屏幕宽度 * 图片高度 / 图片宽度
    this.data.imgheights.push(swiperH);
    this.data.imgBoxSize = Math.max.apply(null, this.data.imgheights);
    this.setData({
        Hei:`${this.data.imgBoxSize}px`//设置高度
    })
  },
  posterClick() {
    this.setData({
      posterShow: true,
    });
  },
  posterClose() {
    this.setData({
      posterShow: false,
    });
  },
  goodsDetail() { //会员信息
    let urlStr = app.getNetAddresss("plugin.event-registration.api.goods.goods.get-goods-detail");
    app._postNetWork({
      url: urlStr,
      data: {basic_info:1,id:this.data.id},
      success: (resdata) => {
        var res = resdata.data;
        let data = res.data;
        if (res.result == 1) {
          this.setData({
            applyInfo:data,
            endTime:data.time* 1000
          })
        }
      },
      fail: function (res) {
        console.log(res);
      },
    });
  },
  serviceDetail() {
    let urlStr = app.getNetAddresss("goods.customer-service.index");
    app._postNetWork({
      url: urlStr,
      data: {basic_info:1,id:this.data.id},
      success: (resdata) => {
        var res = resdata.data;
        let data = res.data;
        if (res.result == 1) {
          this.setData({
            customer_open:data.customer_open == "1" ? true : false,
            cservice: res.data.cservice,
            service_QRcode: data.service_QRcode,
            service_mobile: data.service_mobile,
          })
        }
      },
      fail: function (res) {
        console.log(res);
      },
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})